function tip(element) {
	var newObj = document.createElement("DIV");
	var tip = document.createElement("DIV");
	newObj.className = "tip";
	tip.innerHTML = element.innerHTML;
	newObj.appendChild(tip);
	element.outerHTML = newObj.outerHTML;
}

function ingredients(element) {
	var newObj = document.createElement("DIV");
  var title = document.createElement("DIV");
  var content = document.createElement("DIV");
  title.setAttribute("isTitle", "true");	
	title.innerHTML = "Ingredienti";
  content.innerHTML = element.innerHTML;
  content.setAttribute("isContent", "true");	
  newObj.appendChild(title);
  newObj.appendChild(content); 
  newObj.className = "ingredients";
	element.outerHTML = newObj.outerHTML;
}

function tools(element) {
	var newObj = document.createElement("DIV");
  var title = document.createElement("DIV");
  var content = document.createElement("DIV");
  title.setAttribute("isTitle", "true");	
	title.innerHTML = "Attrezzature consigliate";
  content.innerHTML = element.innerHTML;
  content.setAttribute("isContent", "true");	
  newObj.appendChild(title);
  newObj.appendChild(content); 
  newObj.className = "tools";
	element.outerHTML = newObj.outerHTML;
}

function process(element) {
	var newObj = document.createElement("DIV");
  var title = document.createElement("DIV");
  var content = document.createElement("DIV");
  title.setAttribute("isTitle", "true");	
	title.innerHTML = "Procedimento";
  content.innerHTML = element.innerHTML;
  content.setAttribute("isContent", "true");	
  newObj.appendChild(title);
  newObj.appendChild(content); 
  newObj.className = "process";
	element.outerHTML = newObj.outerHTML;
}

function image(element)
{
	var newObj = document.createElement("DIV");
	var imgContainer = document.createElement("DIV");
	var img = document.createElement("IMG");
	var label = document.createElement("DIV");
  var a = document.createElement("A");
  a.setAttribute("href", element.getAttribute("src"));
  a.setAttribute("imageanchor", "1");
	img.setAttribute("alt", "");
	img.setAttribute("src", element.getAttribute("src"));
	img.setAttribute("width", element.getAttribute("width"));
	img.setAttribute("height", element.getAttribute("height"));
	label.innerText = element.getAttribute("alt");
	newObj.className = "image";
	imgContainer.setAttribute("style", "width:" + element.getAttribute("width") + "px;");
	label.setAttribute("style", "width:" + element.getAttribute("width") + "px;");
  a.appendChild(img);
	imgContainer.appendChild(a);
	newObj.appendChild(imgContainer);
	newObj.appendChild(label);
	element.outerHTML = newObj.outerHTML;
}


function initializeUI() {
	var tags = document.getElementsByTagName("*");
	for (var i = 0; i < tags.length; i++) {
		var tagName = tags.item(i).nodeName;
		if (tagName.toLowerCase() == "tip") {
			obj = tags.item(i)
			tip(obj);
		}
		else if(tagName.toLowerCase() == "ingredients") {
			obj = tags.item(i)
			ingredients(obj);
		}
		else if(tagName.toLowerCase() == "tools") {
			obj = tags.item(i)
			tools(obj);
		}
		else if(tagName.toLowerCase() == "process") {
			obj = tags.item(i)
			process(obj);
		}
		else if(tagName.toLowerCase() == "postimage"){
			obj = tags.item(i);
			image(obj);
		}
	}
}

// Dean Edwards/Matthias Miller/John Resig

function init() {
  // quit if this function has already been called
  if (arguments.callee.done) return;

  // flag this function so we don't do the same thing twice
  arguments.callee.done = true;

  // kill the timer
  if (_timer) clearInterval(_timer);

  // do stuff
  initializeUI();
};

/* for Mozilla/Opera9 */
if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
  document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
  var script = document.getElementById("__ie_onload");
  script.onreadystatechange = function() {
	if (this.readyState == "complete") {
	  init(); // call the onload handler
	}
  };
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
  var _timer = setInterval(function() {
	if (/loaded|complete/.test(document.readyState)) {
	  init(); // call the onload handler
	}
  }, 10);
}

/* for other browsers */
window.onload = init;

